import Trans from '../../../main/js/com/1110111011101110/Trans.js'
import StrTo from '../utils/StrTo.js'
import fs from 'fs';
import Row from "../../../main/js/com/1110111011101110/basics/Row";

let trans= new  Trans()
let fsPath="./测试.jsr"
let data=fs.readFileSync(fsPath);
trans.loadData(data)



class Run{
    static  run(str){

        let wordIds= this. word(str);

        console.log("数据 文字  "+str   +"       数据ID："+wordIds)
        let wordsId=  this.words(wordIds)
        debugger
        console.table("词 ："+wordsId.toString())
    }

    analysis(){

    }


    /**
     * 字
     * @param strNums
     */
    static word(str){
        //拆分直接添加
        let res=[];
        let srts=str.split("");
        for(let i=0;i<srts.length;i++){
            let num= StrTo.utf8ToNum(srts[i]);
            let wordId =trans.addWord(num);
            res.push(wordId)
        }
        return res;

    }

    /**
     * 通过字或者词添加意
     * 意
     */
    idea(){
        //判断是字还是词
        //    如果是词查找是否存在，不存在创建
        //查找意是否存在，不存在创建

    }

    /**
     * 组词
     */
    static  words(wordIds){
        return  trans.addWrods(wordIds[0],wordIds[1])
        //查找每个字是否存在
        //组词 某认情况下不创建，除非添加意
    }


    static idea(str,idea){
        let wordIds= this. word(str);
        let wordsIds= this. word(idea);
        let idesssIdss=this.words(wordsIds);

        console.log("字："+str  +"      意："+idea)
     /*   let row =new Row(idesssIdss.find(3),5);
        trans.addReal(row,wordIds[0])

        let real=   trans.findReal(null,wordIds[0])*/

    }


}


process.stdin.setEncoding('utf8');

process.stdin.on('readable', () => {

    var chunk = process.stdin.read();
    if(typeof chunk === 'string'){
        chunk = chunk.slice(0,-1);
        process.stdout.write(`stringLength:${chunk.length}\n`);
    }
    if(chunk === ''){
        process.stdin.emit('end');
        return
    }
    if (chunk !== null) {
        let s=chunk.trim().split(/\s+/)
        let ids=   Run.idea(s[0],s[1])
        process.stdout.write(`数据: ${chunk }   ${ids} \n`);
    }
});

process.stdin.on('end', () => {
    let data=  trans.outData();
    // 往writeme.txt文件 写入一些内容
    fs.writeFile(fsPath, data, function (err) {
        // 判断 如果有错 抛出错误 否则 打印写入成功
        if (err) {
            throw err;
        }
        console.log('写入文件成功!')
    })

    process.stdout.write('结束');
});

